package ThreadTest.Homework;
/*
输出奇数的线程
 */
public class OddThread extends Thread {
    Num num;

    public OddThread(Num num) {
        this.num = num;
    }

    public void run(){
        synchronized (num){
            while(true){
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                if(num.getI() % 2 == 0){
                    try {
                        num.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }else {
                    int i = num.getI();
                    System.out.println(Thread.currentThread().getName()+"-->"+i);
                    num.setI(++i);
                    num.notify();
                }
            }
        }
    }
}
